let arr = [1,2,6,7,1,0,2,54,63,9]
function mergeSort(arr){
    if(arr.length>1){
        let middle = Math.floor(arr.length/2);// 取中间的数组下标
        let left = mergeSort(arr.slice(0, middle));
        let right = mergeSort(arr.slice(middle, arr.length));
        arr = merge(left, right);
    }
    return arr;
}
// [3,6,9,12] [10,11,341,3241,1243234,123123124,3453453]
// [3.6.9.10.11.12] [341,3241,1243234,123123124,3453453]
function merge(left, right){
    let i = 0;
    let j = 0;
    let result = [];
    while(i < left.length&&j<right.length){
        result.push((left[i]<right[j])?left[i++]:right[j++]);
    }
    return result.concat( i < left.length?left.slice(i):right.slice(j));
}
console.log(arr)
console.time('归并排序的时间');
mergeSort(arr)
console.timeEnd('归并排序的时间')
console.log(arr)